home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / wtmp.c < prev   
C/C++ Source or Header  |  1993-09-15  |  848b  |  42 lines

  1. /*
  2.  * BSD style wtmp updating routine Version 1.0 (c) S.R.Usher 1991.
  3.  * Modified 910126 dpg: uses non-buffered file ops, like utmp.c
  4.  */
  5.  
  6. #include <fcntl.h>
  7. #include <unistd.h>
  8. #include <string.h>
  9. #include <utmp.h>
  10.  
  11. #define WTMP_FILE    "/var/adm/wtmp"
  12.  
  13. void _write_wtmp(line, name, host, time)
  14. const char *line, *name, *host;
  15. unsigned long time;
  16. {
  17.     int fd;
  18.     struct utmp entry;
  19.  
  20.     if ((fd = open(WTMP_FILE, O_WRONLY | O_APPEND)) < 0)
  21.     {
  22. #ifdef DEBUG
  23.         perror("_write_wtmp");
  24. #endif
  25.         return;
  26.     }
  27.  
  28. /*
  29.  * Note, doing this in this order means that it doesn't matter about the Null
  30.  * bytes strncpy adds the the strings if they are greater than 8/16 bytes!
  31.  */
  32.  
  33.     strncpy(entry.ut_line, line, 8);
  34.     strncpy(entry.ut_name, name, 8);
  35.     strncpy(entry.ut_host, host, 16);
  36.     entry.ut_time = time;
  37.  
  38.     write(fd, &entry, (unsigned) sizeof(struct utmp));
  39.  
  40.     close(fd);
  41. }
  42.